package Loganseabolt.tools;

import java.util.ArrayList;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class Soul extends Item{

	public Soul(int par1) {
		super(par1);
		setCreativeTab(CreativeTabs.tabMaterials);
		// TODO Auto-generated constructor stub
	}
	public void registerIcons(IconRegister iconReg)
    {
        itemIcon = iconReg.registerIcon("LoganSeaboltModBase:soul");
    }
	public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
	{
		ArrayList<EntityLiving> List1= new ArrayList<EntityLiving>(); 
	    if (par2World.loadedEntityList == null)
	    	return par1ItemStack;
	    if (!par3EntityPlayer.capabilities.isCreativeMode)
        {
            --par1ItemStack.stackSize;
        }
	    for(Object _Entity: par2World.loadedEntityList)
	    {
	    	EntityLiving temp;
	    	try
	    	{
	    		temp = (EntityLiving) _Entity;
	    	}
	    	catch(Exception e)
	    	{
	    		continue;
	    	}
	    	if(temp != null)
	    	{
	    		if (temp.getPosition(1).distanceTo(par3EntityPlayer.getPosition(1)) < 10)
	    		{
	    			float speed = 10;
	    			Vec3 diffVec = par3EntityPlayer.getPosition(1).subtract(temp.getPosition(1));
	    			diffVec = diffVec.normalize();
	    			diffVec = Vec3.createVectorHelper(diffVec.xCoord * speed, diffVec.yCoord * 3, diffVec.zCoord*speed);
	    			temp.setVelocity(diffVec.xCoord, diffVec.yCoord, diffVec.zCoord);
	    		}
	    	}
	    	par1ItemStack.stackSize--;
	    }
	    return par1ItemStack;
	}
}
